//
//  BLNavigationController.m
//  beautyLamp
//
//  Created by Tam Kwok To Michael on 2017/8/9.
//  Copyright © 2017年 Tam Kwok To Michael. All rights reserved.
//

#import "BLNavigationController.h"
#import "BLHeader.h"

@interface BLNavigationController () <UINavigationControllerDelegate>

@end

@implementation BLNavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
}

- (void)setupUI {
    NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:THEMECOLOR, NSForegroundColorAttributeName, nil];
    [[UINavigationBar appearance] setTitleTextAttributes:attributes];
    [[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]];
    
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
    self.delegate = self;

}


- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    if (navigationController.viewControllers.count > 1 && navigationController.viewControllers.count != 5) {
        //back_orange back_normal
        UIBarButtonItem *back = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"back_normal"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(backBtnEvent)];
        viewController.navigationItem.leftBarButtonItem = back;
    }
}

- (void)backBtnEvent {
    [self popViewControllerAnimated:YES];
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    if( self.viewControllers.count > 0) {
        [viewController setHidesBottomBarWhenPushed:YES];
    }
    [super pushViewController:viewController animated:YES];
}
@end
